<template>
	<view class="content">
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" @up="upCallback" :up="upOption" :down="{ use: false }">
			<view style="position: absolute;z-index: 10076;background-color: #FFFFFF;width: 100%;">
				<u-picker
					:show="showType"
					keyName="dict_label"
					:columns="typeList"
					closeOnClickOverlay
					@cancel="showType = false"
					@close="showType = false"
					@confirm="_setCurType"
				></u-picker>
			</view>
			<view class="section-0">
				<view class="section-body">
					<view class="form">
						<view class="form-item">
							<view class="label">物料描述</view>
							<view class="shape"></view>
							<view class="input">
								<u--input placeholderClass="input-placeholder" class="input-body" placeholder="请填写物料描述" v-model="form.describe"></u--input>
							</view>
						</view>
						<view class="form-item">
							<view class="label">批次</view>
							<view class="shape"></view>
							<view class="input">
								<u--input placeholderClass="input-placeholder" class="input-body" placeholder="请填写批次" v-model="form.number"></u--input>
							</view>
						</view>
						<!-- <view class="form-item" >
						<view class="label">状态</view>
						<view class="shape"></view>
						<view class="input">
							<u--input placeholderClass="input-placeholder" class="input-body" placeholder="状态"
								v-model="form.status" ></u--input>
						</view>
					</view> -->
						<view class="form-item">
							<view class="label">状态</view>
							<view class="shape"></view>
							<view class=" picker" @click="showType = true">
								<text v-if="curType">{{ curType }}</text>
								<text v-else class="curType">请选择状态</text>

								<text class="iconfont icon-xiala"></text>
							</view>
						</view>
						<view class="form-item">
							<view class="label">退料项目名称</view>
							<view class="shape"></view>
							<view class="input">
								<u--input placeholderClass="input-placeholder" class="input-body" placeholder="请填写退料项目名称" v-model="form.project_name"></u--input>
							</view>
						</view>
						<view class="form-item">
							<view class="label">大类描述</view>
							<view class="shape"></view>
							<view class="input">
								<u--input placeholderClass="input-placeholder" class="input-body" placeholder="请填写大类描述" v-model="form.big_cate_des"></u--input>
							</view>
						</view>
						<view class="form-item">
							<view class="label">中类描述</view>
							<view class="shape"></view>
							<view class="input">
								<u--input placeholderClass="input-placeholder" class="input-body" placeholder="请填写中类描述" v-model="form.mid_cate_des"></u--input>
							</view>
						</view>
						<view class="form-item">
							<view class="label">小类描述</view>
							<view class="shape"></view>
							<view class="input">
								<u--input placeholderClass="input-placeholder" class="input-body" placeholder="请填写小类描述" v-model="form.small_cate_des"></u--input>
							</view>
						</view>
						<view class="form-item">
							<view class="label">供应商</view>
							<view class="shape"></view>
							<view class="input">
								<u--input placeholderClass="input-placeholder" class="input-body" placeholder="请填写供应商" v-model="form.supplier"></u--input>
							</view>
						</view>
						<view class="actions">
							<view class="action" @click="handleResetForm()">
								<text>重</text>
								<text>置</text>
							</view>
							<view class="action search" @click="handleSearch()">
								<text>查</text>
								<text>询</text>
							</view>
						</view>
					</view>
					<view class="list" @click="go(item)" v-for="(item, index) in list" :key="index">
						<view class="labels labels1" v-if="item.status == 1">可利库</view>
						<view class="labels labels2" v-else-if="item.status == 2">不可利库</view>
						<view class="labels labels3" v-else-if="item.status == 3">已推派</view>
						<view class="labels" v-else>待核实</view>
						<view class="serialnumber">序号：{{ index + 1 }}</view>
						<view class="describe describe1">
							<text>物料描述：</text>
							{{ item.describe }}
						</view>
						<view class="describe">
							<text>供应商：</text>
							{{ item.supplier }}
						</view>
						<view class="describe">
							<text>退料项目名称：</text>
							{{ item.project_name }}
						</view>
						<view class="describe describe2">
							<view class="batchdescription">
								<text>批次：</text>
								{{ item.number }}
							</view>
							<view class="">
								<text>大类描述：</text>
								{{ item.big_cate_des }}
							</view>
						</view>
						<view class="describe describe2">
							<view class="batchdescription">
								<text>小类描述：</text>
								{{ item.small_cate_des }}
							</view>
							<view class="">
								<text>中类描述：</text>
								{{ item.mid_cate_des }}
							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
import formArea from '@/components/form_area/index.vue'
import { materialInventoryListApi } from '@/api/statistics.js'
export default {
	components: { formArea },
	data() {
		return {
			showType: false,
			form: {
				project_name: '',
				city: '',
				status: ''
			},
			list: [],
			list2:[],
			mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
			upOption: {
				textNoMore: '-- 没有更多了 --'
			},
			pageSize: 20,
			curType: '',
			status: '',
			typeList: [
				[
					{
						dict_label: '可利库',
						status: '1'
					},
					{
						dict_label: '不可利库',
						status: '2'
					},
					{
						dict_label: '已推派',
						status: '3'
					},
					{
						dict_label: '待核实',
						status: '4'
					}
				]
			]
		}
	},
	methods: {
		_setCurType(e) {
			this.curType = e.value[0].dict_label
			this.status = e.value[0].status
			this.showType = false
		},
		go(item) {
			uni.navigateTo({
				url: '/pages/statistics/material/inventory_List/details/index?params=' + JSON.stringify(item)
			})
		},
		// 重置
		handleResetForm() {
			for (let key in this.form) {
				this.form[key] = ''
			}
			this.curType = ''
			this.status = ''
			this.mescroll.resetUpScroll()
			this.mescroll.scrollTo(0, 0)
		},
		// 查询
		handleSearch() {
			this.mescroll.resetUpScroll()
			this.mescroll.scrollTo(0, 0)
		},
		/*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
		mescrollInit(mescroll) {
			this.mescroll = mescroll
		},
		/*上拉加载的回调*/
		async upCallback(page) {
			const { data } = await materialInventoryListApi({
				...this.form,
				status: this.status,
				page: page.num,
				pageSize: this.pageSize
			})
			if (data.code === 1 || data.code === 200) {
				this.list2 = []
				this.list2 = data.data.data
				// 接口返回的当前页数据列表 (数组)
				let curPageData = this.list2
				// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
				let curPageLen = curPageData.length
				// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
				let totalPage = data.data.total
				//设置列表数据
				if (page.num == 1) this.list = [] //如果是第一页需手动置空列表
				this.list = this.list.concat(curPageData) //追加新数据
				// 请求成功,隐藏加载状态
				this.mescroll.endByPage(curPageLen, totalPage)
				setTimeout(() => {
					this.mescroll.endSuccess(curPageLen)
				}, 20)
			} else {
				//  请求失败,隐藏加载状态
				this.mescroll.endErr()
			}
		}
	}
}
</script>
<style lang="scss" scoped>
.content {
	width: 100%;
	.section-0 {
		width: 100%;
		background: #2e5efe;
		position: relative;
		z-index: 10;
		.section-body {
			width: 100%;
			height: 100%;
			padding-bottom: 50rpx;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			background-color: #fff;
			overflow: hidden;
			.form {
				width: 100%;
				padding: 0 75rpx;
				padding-top: 40rpx;
				box-sizing: border-box;
				border-bottom: 2rpx solid #d8e4f2;
				.form-item {
					width: 600rpx;
					height: 48rpx;
					border-radius: 20rpx;
					border: solid 2rpx #1534ce;
					margin: 0 auto;
					margin-bottom: 25rpx;
					&:last-child {
						margin-bottom: 34rpx;
					}
					@include clear();
					.label {
						float: left;
						width: 170rpx;
						height: 48rpx;
						text-align: center;
						line-height: 44rpx;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: #1534ce;
					}
					.picker {
						text {
							margin-left: 30rpx;
							font-size: 26rpx;
							letter-spacing: 0rpx;
							color: rgba(0, 0, 0, 0.7);
						}
						.iconfont {
							float: right;
							margin-right: 10rpx;
							margin-top: 8rpx;
							font-size: 32rpx;
						}
						.curType {
							color: #c0c4cc;
						}
					}
					.shape {
						width: 3rpx;
						height: 32rpx;
						background-color: #7f98ae;
						float: left;
						margin-top: 8rpx;
					}
					.input {
						float: left;
						width: calc(100% - 170rpx - 3rpx);
						.input-body {
							box-sizing: border-box;
							width: 100%;
							height: 44rpx;
							padding: 0 !important;
							border: none;
							padding-left: 30rpx !important;
							padding-right: 30rpx !important;
							font-size: 26rpx;
							font-weight: normal;
							font-stretch: normal;
							letter-spacing: 0rpx;
							color: rgba(0, 0, 0, 0.7);
						}
						.input-placeholder {
							font-size: 26rpx;
							font-weight: normal;
							font-stretch: normal;
							letter-spacing: 0rpx;
							color: rgba(0, 0, 0, 0.5);
						}
					}
				}
				.actions {
					width: 100%;
					height: 50rpx;
					margin-top: 29rpx;
					padding-bottom: 40rpx;
					display: flex;
					justify-content: space-between;
					.action {
						width: 288rpx;
						height: 48rpx;
						background-color: #395cf5;
						border-radius: 20rpx;
						text-align: center;
						line-height: 48rpx;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						line-height: 48rpx;
						color: #ffffff;
						text {
							&:first-child {
								margin-right: 20rpx;
							}
						}
					}
					.search {
						background-color: #1534ce;
					}
				}
			}
			.list {
				width: 670rpx;
				box-sizing: border-box;
				margin-left: 40rpx;
				margin-top: 40rpx;
				padding: 30rpx;
				background-color: #ffffff;
				border-radius: 40rpx;
				webkit-box-shadow: 0px 0px 10px #cccccc;
				moz-box-shadow: 0px 0px 10px #cccccc;
				box-shadow: 0px 0px 10px #cccccc;
				position: relative;
				.labels {
					position: absolute;
					right: 40rpx;
					font-size: 10rpx;
					line-height: 30rpx;
					top: 0rpx;
					width: 40rpx;
					// height: 110rpx;
					padding-top: 15rpx;
					text-align: center;
					background-color: #e09742;
					color: #ffffff;
					padding-bottom: 20rpx;
					border-bottom-left-radius: 50rpx;
					border-bottom-right-radius: 50rpx;
				}
				.labels1 {
					background-color: #13b190;
				}
				.labels2 {
					background-color: #c42217;
				}
				.labels3 {
					background-color: #1e68bf;
				}
				.serialnumber {
					font-weight: bold;
					margin-left: 20rpx;
				}
				.describe {
					font-size: 30rpx;
					// display: flex;
					margin-top: 20rpx;
					color: #a2a2a2;
					text {
						color: black;
					}
					.batchdescription {
						margin-right: 30rpx;
					}
				}
				.describe1 {
					width: calc(100% - 65rpx);
					text {
						width: calc(100% - 200rpx);
					}
				}
				.describe2 {
					display: flex;
				}
			}
		}
	}
}
</style>
